home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / mj90 / ProPage / CLIWindowPtrII-93.ppd (.txt) next >
Encoding:
Professional Page Document  |  1991-06-11  |  25.4 KB  |  203 lines

  1. Professional Page V1.2
  2. dPENV
  3. Helvetica
  4. Bookman
  5. Courier
  6. zapfdingbats
  7. helvetican
  8. VGreen
  9. Yellow
  10. Magenta
  11. VCyan
  12. %bPDOC
  13. cwptrII93.ppg
  14. MAdam Levin
  15. Disabling Sprite DMA from a Vertical Blank Interrupt
  16. M#PTXT
  17. Z\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black>U259 U260 U261 U262\.
  18. W\n\ff<helvetican>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Socketed Chip RAM\.
  19. BPTXT
  20. X\n\ff<helvetican>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Soldered Chip\MRAM\.
  21. ePTXT
  22. Z\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black>U263 U264 U265 U266\.
  23. Z\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black>U271 U272 U273 U274\.
  24. y\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black>                               U267 U268 U269 U270\.
  25. ?PPAG
  26. XPSGR
  27. Black
  28. Black
  29. bPTXT
  30. N\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page\.
  31. d\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>MIDI Output in Assembler  \.
  32. XrPTXT
  33. `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times>
  34. xlPBOX
  35. Black
  36. Black
  37. LPBOX
  38. BPBOX
  39. Black
  40. Black
  41. ^PBOX
  42. &PTXT
  43. ]\n\B\ff<Courier>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>MIDI Output in Assembler\.
  44. LPBOX
  45. L\n\B\ff<Courier>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page\.
  46. ~PBOX
  47. ^\n\B\I\O\ff<Courier>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times>
  48. =PBOX
  49. ePSGR
  50. Black
  51. Black
  52. X\n\I\ff<Times>\fs<12>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>January/February 1990\.
  53. CPBOX
  54. \n\ff<Times>\fs<12>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>
  55. \B\fs<30>Using C to Get a Pointer 
  56. to the CLI Window \b\fs<12>
  57. \B\fs<14>by Rob Wyesham\b\fs<12>
  58. Programs sometime need to get a pointer to their CLI window.  A method for obtaining this pointer was illustrated in the \IAmiga Mail\i article entitled "CLIColors.asm - Using ConsolePackets in 68000 Assembler" (page II-65, July/August 1989 \IAmiga Mail\i). However, many C programmers would rather avoid using assembly language.  This article shows how to use C to get a pointer the CLI window.
  59. The basic method is the same whether you use C or Assembler.  You send an  \ff<Courier>\fs<10>ACTION_DISK_INFO\ff<Times>\fs<12> packet to the console handler process which includes a pointer to an InfoData struture. When the packet is returned by AmigaDOS, the id_VolumeNode field of the InfoData structure will be filled in with a pointer to the CLI window that the console handler is using.
  60. The program below, WindowPtr.c\I,\i follows the code of CLIColors.asm closely.  Like the latter program, the strategy behind WindowPtr.c is to:
  61. \s\ff<zapfdingbats>\lr<160>o\ff<Times> Make sure the program was launched from a CLI.
  62. \s\ff<zapfdingbats>o\ff<Times> Send an \ff<Courier>\fs<10>ACTION_DISK_INFO\ff<Times>\fs<12> packet.
  63. \s\ff<zapfdingbats>\lr<120>o\ff<Times> Extract the window pointer from the information 
  64. \s\sreturned in the packet.
  65. The program starts by examining certain structures to determine if it was launched from a CLI.   If it passes that test, the program checks its Process structure to make sure that it has a valid pointer to a console task.  Next, the program allocates memory for FindWindow, a custom structure composed of a struct StandardPacket and a struct InfoData.  
  66. The program then initializes the StandardPacket fields and sends an \ff<Courier>\fs<10>ACTION_DISK_INFO\ff<Times>\fs<12> packet to the DOS.  When the packet returns, the program checks for an error.  An error could possibly be caused by the CLI not having an associated window.  A CLI that uses the AUX: handler rather than the CON: handler could cause such an error.
  67. \lr<115>If the packet returns without an error, the id_VolumeNode field of the InfoData structure points to the CLI window.  This is an ordinary C pointer, not a BPTR.  The  program shows that the pointer obtained does indeed point to the current CLI window by printing out a few of the window's parameters.
  68. WindowPtr.c is listed below.  It was compiled under Lattice 5.05 using the command:
  69.  LC -b1 -cfist -L -v -w WindowPtr.c.  Link with lc.lib and amiga.lib.\fs<9>
  70. \ff<Courier>\lr<120>/*
  71. * File name: windowptr.c
  72.  * Purpose: To illustrate how to get the pointer 
  73. *\s\s\s\sto the current CLI window.
  74.  * Requires: Must be started from a CLI
  75. #include <libraries/dosextens.h>\s\s/* Defines the StandardPacket
  76. \s\s\s\s\s\s\s\s\s\s\s * structure, the packet types,
  77. \s\s\s\s\s\s\s\s\s\s\s * and the Process structure
  78. \s\s\s\s\s\s\s\s\s\s\s */
  79. #include <libraries/dos.h>\s\s\s/* Defines the InfoData structure */
  80. \s\s\s\s\s\s\s\s\s\s/* and RETURN_XXX                 */
  81. #include <exec/types.h>
  82. #include <exec/memory.h>\s\s\s/* Defines MEMF_XXX */
  83. #include <stdio.h>\s\s\s\s\s/* Defines NULL and stdout */
  84. #include <stdlib.h>\s\s\s\s\s/* Declares exit() */
  85. #include <proto/exec.h>
  86. #include <proto/intuition.h>
  87. /* Set up the FindWindow structure. */
  88. struct FindWindow
  89. \sstruct StandardPacket FW_Pack;\s\s/* A StandardPacket is all long-words */
  90. \sstruct InfoData\s FW_Info;\s\s\s/* so InfoData is long-word-aligned   */
  91. };\s\s\s\s\s\s\s\s\s\s\s/* if the FindWindow struct is.       */
  92. #define THISTASK NULL
  93. extern VOID cleanExit( struct FindWindow *, int );\lr<115>
  94. VOID main( int argc, char *argv[] )
  95. \sstruct Process *myProcess = NULL;
  96. \sstruct FindWindow *thisWindow = NULL;
  97. \sstruct Window *addrThisWindow = NULL;
  98. \sSHORT minW, minH;
  99. \sUSHORT maxW, maxH;
  100. \sSHORT xPos, yPos, W, H;
  101. \s/* Get address of the current task */
  102. \smyProcess = (struct Process *)FindTask( THISTASK );
  103. \s/* Make sure this program wasn't started from Workbench */
  104. \sif ( argc == 0 ) cleanExit( thisWindow, RETURN_WARN );
  105. \s/* Make sure that there is a pr_ConsoleTask */
  106. \sif ( myProcess->pr_ConsoleTask == NULL )
  107. \s\scleanExit( thisWindow, RETURN_WARN );
  108. \s/* Allocate memory for the FindWindow structure */
  109. \sthisWindow = (struct FindWindow *)
  110. \s\s      AllocMem( sizeof( struct FindWindow ), MEMF_PUBLIC|MEMF_CLEAR );
  111. \sif ( thisWindow == NULL ) cleanExit( thisWindow, RETURN_WARN );
  112. \s/* Initialize the packet */
  113. \sthisWindow->FW_Pack.sp_Msg.mn_Node.ln_Name = 
  114. \s                             (char *)&thisWindow->FW_Pack.sp_Pkt;
  115. \sthisWindow->FW_Pack.sp_Pkt.dp_Link = (struct Message *)thisWindow;
  116. \sthisWindow->FW_Pack.sp_Pkt.dp_Port = &myProcess->pr_MsgPort;
  117. \sthisWindow->FW_Pack.sp_Pkt.dp_Type = ((LONG)&thisWindow->FW_Info) >> 2;
  118. \s/* Now send the packet, and wait for it to return */
  119. \sPutMsg( (struct MsgPort *)myProcess->pr_ConsoleTask,
  120. \s                                (struct Message *)thisWindow );
  121. \s(void)WaitPort( (struct MsgPort *) &myProcess->pr_MsgPort );
  122. \s/* Our program has been replied to, so get the reply message */
  123. \s(void)GetMsg( &myProcess->pr_MsgPort );
  124. \s/* Save the address of the CLI window */
  125. \saddrThisWindow = (struct Window *) (&(thisWindow->FW_Info))->id_VolumeNode;
  126. \s/* If there was an error, terminate execution */
  127. \sif ( thisWindow->FW_Pack.sp_Pkt.dp_Res1 == DOSFALSE )
  128. \s\s\s\scleanExit( thisWindow, RETURN_WARN );
  129. \sif ( addrThisWindow == NULL ) cleanExit( thisWindow, RETURN_WARN );
  130. /* Get the position, dimensions, and minimum and maximum
  131. \s * dimensions of the currently active CLI window */
  132. \sxPos = addrThisWindow->LeftEdge;
  133. \syPos = addrThisWindow->TopEdge;
  134. \sW = addrThisWindow->Width;
  135. \sH = addrThisWindow->Height;
  136. \sminW = addrThisWindow->MinWidth;
  137. \sminH = addrThisWindow->MinHeight;
  138. \smaxW = addrThisWindow->MaxWidth;
  139. \smaxH = addrThisWindow->MaxHeight;
  140. \s/* Print the position, dimensions, and minimum and maximum
  141. \s * dimensions of the currently active CLI window */
  142. \sprintf( "Position: x = %d, y = %d   ", xPos, yPos );
  143. \sprintf( "Dimensions: w = %d, h = %d\\n", W, H );
  144. \sprintf( "%d <= width <= %d   ", minW, maxW );
  145. \sprintf( "%d <= height <= %d\\n", minH, maxH );
  146. \scleanExit( thisWindow, RETURN_OK );
  147. VOID cleanExit( pktptr, returnValue )
  148. struct FindWindow *pktptr;
  149. int returnValue;
  150. \sif ( pktptr ) FreeMem( pktptr, (LONG)sizeof( struct FindWindow ) );
  151. \sexit( returnValue );
  152. \fs<10>
  153. \B\I\O\ff<Bookman>\fs<14>A\b\i\o\ff<Times>\fs<12>
  154. kPBOX
  155. kPSGR
  156. Black
  157. Black
  158. mPBOX
  159. q\n\B\ff<Helvetica>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Using C to Get a Pointer to the CLI Window\.
  160. !PBOX
  161. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page II - 93\.
  162. uPTXT
  163. S\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga DOS\.
  164. `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times>
  165. Black
  166. Black
  167. :YPBOX
  168. P\n\I\ff<Times>\fs<12>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>May/June 1990\.
  169. V>PPAG
  170. XCPSGR
  171. Black
  172. Black
  173. b    PTXT
  174. O\n\B\ff<Helvetica>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>AmigaDOS\.
  175. ~/PTXT
  176. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page II - 94\.
  177. OPTXT
  178. v\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>  Using C to Get a Pointer to the CLI Window\.
  179. `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times>
  180. Black
  181. Black
  182. aPBOX
  183. Black
  184. Black
  185. q\n\B\ff<Helvetica>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Using C to Get a Pointer to the CLI Window\.
  186. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page II - 95\.
  187. R\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>AmigaDOS\.
  188. ^8PTXT
  189. U\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\.
  190. zPPBOX
  191. Black
  192. Black
  193. Black
  194. Black
  195. APBOX
  196. O\n\B\ff<Helvetica>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>AmigaDOS\.
  197. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page II - 96\.
  198. iPBOX
  199. t\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Using C to Get a Pointer to the CLI Window\.
  200. `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times>
  201. Black
  202. Black
  203.